package cn.com.connext.scrm.repository.master;

import cn.com.connext.scrm.domain.master.NoteLikes;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;


@Repository
public interface NoteLikesRepository extends JpaSpecificationExecutor, JpaRepository<NoteLikes, String> {

    @Query("select count(a) from NoteLikes a where a.noteId = :noteId")
    Integer countAllByNoteId(@Param("noteId") String noteId);

    ///根据noteId和userId查询是否已点赞
    NoteLikes findOneByNoteIdAndUserId(String noteId, String userId);

    @Query("select noteId from NoteLikes a where a.userId = :userId")
    List<String> findNoteIdsByUserId(@Param("userId") String userId);

    @Query(value = "select note.note_id as noteId,count(1) as counts from note_likes note  group by note.note_id", nativeQuery = true)
    List<Object[]> countAll();
}
